package com.situ.mall.controller;

import com.situ.mall.pojo.*;
import com.situ.mall.service.IShippingService;
import com.situ.mall.util.Result;
import jakarta.servlet.http.HttpSession;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

@RestController
@RequestMapping("/shipping")
public class ShippingController {
    @Autowired
    private IShippingService shippingService;

    @RequestMapping("/list")
    public Result list(HttpSession session) {
        User user = (User) session.getAttribute("user");
        List<Shipping> list = shippingService.list(user.getId());
        return Result.ok(list);
    }

    @RequestMapping("/selectProvince")
    public Result selectProvince(){
        List<Province> provinces = shippingService.selectProvince();
        return Result.ok(provinces);
    }

    @RequestMapping("/selectCity")
    public Result selectCity(Integer provinceId){
        List<City> cities = shippingService.selectCity(provinceId);
        return Result.ok(cities);
    }

    @RequestMapping("/selectArea")
    public Result selectArea(Integer cityId){
        List<Area> areas = shippingService.selectArea(cityId);
        return Result.ok(areas);
    }

    @RequestMapping("/add")
    public Result add(Shipping shipping,HttpSession session){
        User user = (User) session.getAttribute("user");
        shipping.setUserId(user.getId());
        shippingService.add(shipping);
        return Result.ok("添加成功");
    }

    @RequestMapping("/delete")
    public Result delete(Integer id){
        shippingService.delete(id);
        return Result.ok("删除成功");
    }
}
